//
//  THHomeSegeViewController.m
//  TreeHole
//
//  Created by apple on 2020/7/27.
//  Copyright © 2020 stoneobs. All rights reserved.
//

#import "THHomeSegeViewController.h"
#import "THChildSelectViewController.h"
@interface THHomeSegeViewController ()<UIScrollViewDelegate>

@end

@implementation THHomeSegeViewController
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super init];
    if (self) {
        self.scrollView = [[UIScrollView alloc] initWithFrame:frame];
        self.scrollView.bounces = NO;
        self.scrollView.showsHorizontalScrollIndicator = NO;
    }
    return self;
}
- (void)loadView{
    self.view = [UIView.alloc initWithFrame:self.scrollView.bounds];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.scrollView];
    [self stoneobs_ui_configSubView];
    // Do any additional setup after loading the view.
}

#pragma mark --configSubView
- (void)stoneobs_ui_configSubView{
    NSInteger i = 0;
    ({
        THChildSelectViewController * vc = THChildSelectViewController.new;
        [self addChildViewController:vc];
        [self.scrollView addSubview:vc.view];
        vc.view.left = UISCREEN_WIDTH * i;
        [vc reload_data_with_selcted_index:i];
        i++;
    });
    ({
        THChildSelectViewController * vc = THChildSelectViewController.new;
        [self addChildViewController:vc];
        [self.scrollView addSubview:vc.view];
        vc.view.left = UISCREEN_WIDTH * i;
        [vc reload_data_with_selcted_index:i];
        i++;
    });
    ({
        THChildSelectViewController * vc = THChildSelectViewController.new;
        [self addChildViewController:vc];
        [self.scrollView addSubview:vc.view];
        vc.view.left = UISCREEN_WIDTH * i;
        [vc reload_data_with_selcted_index:i];
        i++;
    });
    self.scrollView.contentSize = CGSizeMake(UISCREEN_WIDTH * i, 0);
    self.scrollView.pagingEnabled = YES;
    self.scrollView.alwaysBounceVertical = NO;
}

- (UIScrollView*)current_sub_h_scroll_view{
    NSInteger index = self.scrollView.contentOffset.x / UISCREEN_WIDTH;
    UIViewController * vc = self.childViewControllers[index];
    for (UIView * view in vc.view.subviews) {
        if ([view isKindOfClass:UIScrollView.class]) {
            return view;
        }
    }
    return nil;
}
@end
